package com.sgb.kjwl.view.ui.activity.leaseAsk;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import com.flyco.tablayout.listener.OnTabSelectListener;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityMapLeaseForFindBinding;
import com.sgb.kjwl.di.machine.DaggerMachineComponent;
import com.sgb.kjwl.di.machine.MachineModule;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.view.ui.fragment.machine.MapLeaseFragment;
import com.sgb.kjwl.viewmodel.machine.MapLeaseModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.recyclerview.adapter.FragPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;
@Deprecated
public class MapLeaseActivity extends AppActivity {

    @Inject
    MapLeaseModel viewModel;

    private ActivityMapLeaseForFindBinding binding;
    private FragPagerAdapter pagerAdapter;
    private ArrayList<Fragment> mFragments;
    private String[] titles;
    private String cid = "";
    private List<PickSelectEntity> cidList = new ArrayList<>();
    private List<PickSelectEntity> typeDatas = new ArrayList<>();
    private List<PickSelectEntity> scalDatas = new ArrayList<>();
    private List<PickSelectEntity> statusDatas = new ArrayList<>();
    private List<PickSelectEntity> teamDatas = new ArrayList<>();

    private String teamNo = "";
    private String typeNo = "";
    private String scalNo = "";
    private String statusNo = "";

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerMachineComponent.builder().appComponent(appComponent)
                .machineModule(new MachineModule(this))
                .build()
                .inject(this);
    }

    public static void start(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, MapLeaseActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_map_lease_for_find);
        binding.ivBack.setVisibility(View.VISIBLE);
        binding.ivBack.setOnClickListener(view -> finish());
    }

    @Override
    protected void init() {
        cid = getIntent().getStringExtra("cid");
//        viewModel.getFilterTypeModel(cid);
//        viewModel.getScaleData();
        setStatusDatas();
        setTeamDatas();

        mFragments = new ArrayList<>();
        titles = new String[3];
        for (int i = 0; i < 3; i++) {
            mFragments.add(MapLeaseFragment.newInstance("", i));
            titles[i] = "类型_"+i;
        }
        pagerAdapter = new FragPagerAdapter(getSupportFragmentManager(), mFragments);
        binding.viewpager.setAdapter(pagerAdapter);
        binding.viewpager.setOffscreenPageLimit(titles.length - 1);
        binding.tablayout.setViewPager(binding.viewpager, titles);

    }

    public void showTypeView(List<PickSelectEntity> datas) {
        if (datas == null || datas.size() == 0) {
            return;
        }

        cidList = datas;

        mFragments = new ArrayList<>();
        int size = datas.size();
        titles = new String[size];
        for (int i = 0; i < size; i++) {
            mFragments.add(MapLeaseFragment.newInstance(datas.get(i).getNo(), i));
            titles[i] = datas.get(i).getProjectscale();
        }
        pagerAdapter = new FragPagerAdapter(getSupportFragmentManager(), mFragments);
        binding.viewpager.setAdapter(pagerAdapter);
        binding.viewpager.setOffscreenPageLimit(titles.length - 1);
        binding.tablayout.setViewPager(binding.viewpager, titles);

        if(null!=cidList && cidList.size()>0){
//            viewModel.getFilterTypeData(cidList.get(0).getNo());
        }

        binding.tablayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
//                teamPopWindow.setCid(cidList.get(position).getNo());
            }

            @Override
            public void onTabReselect(int position) {}
        });

    }

    public void changeType(int position) {
        binding.viewpager.setCurrentItem(position);
    }

    public void setTypeDatas(List<PickSelectEntity> datas) {
        typeDatas.clear();
        PickSelectEntity entity = new PickSelectEntity();
        entity.setNo("0");
        entity.setProjectscale("全部");
        typeDatas.add(0,entity);
        typeDatas.addAll(datas);
    }

    public void setStatusDatas() {
        statusDatas.clear();
        PickSelectEntity entity = new PickSelectEntity();
        entity.setNo("-1");
        entity.setProjectscale("全部");
        PickSelectEntity entity1 = new PickSelectEntity();
        entity1.setNo("1");
        entity1.setProjectscale("可出工");
        PickSelectEntity entity2 = new PickSelectEntity();
        entity2.setNo("0");
        entity2.setProjectscale("不可出工");
        statusDatas.add(entity);
        statusDatas.add(entity1);
        statusDatas.add(entity2);
    }

    public void setScalDatas(List<PickSelectEntity> datas) {
        scalDatas.clear();
        PickSelectEntity entity = new PickSelectEntity();
        entity.setNo("0");
        entity.setProjectscale("全部");
        scalDatas.add(0,entity);
        scalDatas.addAll(datas);
    }

    public void setTeamDatas() {
        teamDatas.clear();
        PickSelectEntity entity = new PickSelectEntity();
        entity.setNo("-1");
        entity.setProjectscale("全部");
        PickSelectEntity entity1 = new PickSelectEntity();
        entity1.setNo("0");
        entity1.setProjectscale("个人");
        PickSelectEntity entity2 = new PickSelectEntity();
        entity2.setNo("1");
        entity2.setProjectscale("企业");
        teamDatas.add(entity);
        teamDatas.add(entity1);
        teamDatas.add(entity2);
    }
}
